home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / hypercar / xfcn / spttool.cpt / Support Tools eXternals 1.2.5 / card_38837.txt < prev    next >
Text File  |  1990-11-13  |  7KB  |  243 lines

  1. -- card: 38837 from stack: in.5
  2. -- bmap block id: 43907
  3. -- flags: 0000
  4. -- background id: 3858
  5. -- name: NumToHex
  6. ----- HyperTalk script -----
  7. on hideObjects
  8.   hide cd fld "label"
  9.   hide cd fld "label 2"
  10.   hide cd fld "decimal"
  11.   hide cd fld "hex"
  12.   hide cd btn "convert"
  13. end hideObjects
  14.  
  15. on showObjects
  16.   show cd fld "label"
  17.   show cd fld "label 2"
  18.   show cd fld "decimal"
  19.   show cd fld "hex"
  20.   show cd btn "convert"
  21. end showObjects
  22.  
  23.  
  24. -- part 2 (field)
  25. -- low flags: 00
  26. -- high flags: 0002
  27. -- rect: left=103 top=159 right=179 bottom=240
  28. -- title width / last selected line: 0
  29. -- icon id / first selected line: 0 / 0
  30. -- text alignment: 0
  31. -- font id: 3
  32. -- text size: 12
  33. -- style flags: 256
  34. -- line height: 16
  35. -- part name: Decimal
  36. ----- HyperTalk script -----
  37. on ReturnInField
  38.   send mouseUp to cd btn "convert"
  39. end ReturnInField
  40.  
  41. on EnterInField
  42.   send mouseUp to cd btn "convert"
  43. end EnterInField
  44.  
  45.  
  46. -- part 3 (field)
  47. -- low flags: 01
  48. -- high flags: 0000
  49. -- rect: left=45 top=161 right=178 bottom=96
  50. -- title width / last selected line: 0
  51. -- icon id / first selected line: 0 / 0
  52. -- text alignment: 65535
  53. -- font id: 3
  54. -- text size: 10
  55. -- style flags: 0
  56. -- line height: 13
  57. -- part name: label
  58.  
  59.  
  60. -- part 4 (field)
  61. -- low flags: 01
  62. -- high flags: 0000
  63. -- rect: left=45 top=237 right=254 bottom=96
  64. -- title width / last selected line: 0
  65. -- icon id / first selected line: 0 / 0
  66. -- text alignment: 65535
  67. -- font id: 3
  68. -- text size: 10
  69. -- style flags: 0
  70. -- line height: 13
  71. -- part name: label 2
  72.  
  73.  
  74. -- part 5 (field)
  75. -- low flags: 00
  76. -- high flags: 0002
  77. -- rect: left=103 top=234 right=254 bottom=240
  78. -- title width / last selected line: 0
  79. -- icon id / first selected line: 0 / 0
  80. -- text alignment: 0
  81. -- font id: 3
  82. -- text size: 12
  83. -- style flags: 256
  84. -- line height: 16
  85. -- part name: Hex
  86.  
  87.  
  88. -- part 6 (button)
  89. -- low flags: 00
  90. -- high flags: A002
  91. -- rect: left=82 top=191 right=225 bottom=175
  92. -- title width / last selected line: 0
  93. -- icon id / first selected line: 0 / 0
  94. -- text alignment: 1
  95. -- font id: 0
  96. -- text size: 12
  97. -- style flags: 8192
  98. -- line height: 16
  99. -- part name: Convert
  100. ----- HyperTalk script -----
  101. on mouseUp
  102.   put NumToHex(cd fld "decimal") into cd fld "hex"
  103. end mouseUp
  104.  
  105.  
  106.  
  107.  
  108. -- part contents for background part 38
  109. ----- text -----
  110. 33/50
  111.  
  112. -- part contents for card part 3
  113. ----- text -----
  114. Decimal
  115.  
  116. -- part contents for card part 4
  117. ----- text -----
  118. Hex
  119.  
  120. -- part contents for card part 2
  121. ----- text -----
  122. 25567
  123.  
  124. -- part contents for card part 5
  125. ----- text -----
  126. 63DF
  127.  
  128. -- part contents for background part 20
  129. ----- text -----
  130.      This XFCN returns the hexidecimal representation (base 16, 0-F) of a decimal number.
  131.  
  132.      Calling syntax : NumToHex(decimalNumber)
  133.   DECIMALNUMBER: the number to convert.  
  134.  
  135.  
  136. -- part contents for background part 42
  137. ----- text -----
  138. { NumToHex(theNumber) }
  139. { Change a number to a string representing it's hexadecimal value. }
  140. {}
  141. {   brought to you by:      Anup Murarka             Eric Carlson         }
  142. {                       ALINK:  SKEPTIC           ALINK:  cyNic   }
  143. {                                   CIS:  76004,3356         }
  144. {}
  145. {               We are part of the Support Tools Development Group,     }
  146. {               Apple Computer, Inc.      }
  147. {}
  148. {               please DO NOT contack Mac DTS for support of this code!    }
  149. {}
  150. {               please DO contact the authors for support of this code!     }
  151. {}
  152. {               Send comments, bug reports, requests to any of the above   }
  153. {               E-mail addresses or to:}
  154. {}
  155. {                           (one of us)                  }
  156. {                           Apple Computer, Inc.          }
  157. {                           900 E. Hamilton, Ave.          }
  158. {                           Campbell, CA   95008      }
  159. {                           M/S 72-L                     }
  160. {}
  161. {   Copyright:   ┬⌐ 1989, 1990 by Apple Computer, Inc., all rights reserved.     }
  162. {}
  163. { written by Eric Carlson                                        }
  164. { AppleLink:  cyNic                                              }
  165. { modification history                                                                                        }
  166. {          Date                  Initials                                    Comments                                   }
  167. {          ----              ------          --------------------------------------------------}
  168. {       11/20/89         ec            first written                                                               }
  169. {       6/6/90             ec            commented, cleaned code                                                 }
  170. {}
  171. unit NumToHex;
  172.  
  173. interface
  174.     uses
  175.         HyperXCMD;
  176.  
  177.     procedure main (paramPtr: XCmdPtr);
  178.  
  179. implementation
  180.  
  181.     function askedForHelp (paramPtr: XCmdPtr;
  182.                                     syntaxMsg: Str255;
  183.                                     copyRightMsg: Str255): boolean;
  184. {}
  185. {   check to see if the user sent a '?' or a '!' as }
  186. { the only parameter. if so we will respond with }
  187. { the calling syntax or the copyright/version info }
  188. { for this external }
  189. {}
  190.         var
  191.             firstStr: str255;
  192.     begin
  193.         askedForHelp := false;
  194.         if paramPtr^.paramCount = 1 then
  195.             begin
  196.                 ZeroToPas(paramPtr, paramPtr^.params[1]^, firstStr);
  197.                     { what is the first param? }
  198.                 if firstStr = '?' then
  199.                     begin
  200.                         paramPtr^.returnValue := PasToZero(paramPtr, syntaxMsg);
  201.                         askedForHelp := true
  202.                     end  { asked for help }
  203.                 else if firstStr = '!' then
  204.                     begin
  205.                         paramPtr^.returnValue := PasToZero(paramPtr, copyRightMsg);
  206.                         askedForHelp := true
  207.                     end;     { asked for copyright info }
  208.             end;     { one parameter passed }
  209.     end;     { function }
  210.  
  211.     procedure NumberToHex (paramPtr: XCMDPtr);
  212.         const
  213.             LoNibble = $000F;                            { low 4 bits }
  214.         var
  215.             copyRtStr, syntaxStr, tempStr: str255;
  216.             theNumber, hexCount: LONGINT;
  217.             HexDigits: string[16];
  218.     begin
  219.         syntaxStr := 'NumToHex(theNumber)';
  220.         copyRtStr := '┬⌐ 1989,1990 Apple Computer, Inc. v.1.0,  by Eric Carlson.';
  221.         if askedForHelp(paramPtr, syntaxStr, copyRtStr) then                { asking for help? }
  222.             exit(NumberToHex);
  223.         zeroToPas(paramPtr, paramPtr^.params[1]^, tempStr);                  { the value to convert }
  224.         theNumber := StrToNum(paramPtr, tempStr);
  225.  
  226.         HexDigits := '0123456789ABCDEF';          { All of the valid Hex digits}
  227.  
  228.         tempStr[4] := HexDigits[BitAnd(theNumber, loNibble) + 1];      {Add 1 so that we skip over the string length byte}
  229.         theNumber := BSR(theNumber, 4);                                     { shift past the byte we just examined }
  230.         tempStr[3] := HexDigits[BitAnd(theNumber, loNibble) + 1];      {   etcΓǪ }
  231.         theNumber := BSR(theNumber, 4);
  232.         tempStr[2] := HexDigits[BitAnd(theNumber, loNibble) + 1];
  233.         theNumber := BSR(theNumber, 4);
  234.         tempStr[1] := HexDigits[BitAnd(theNumber, loNibble) + 1];
  235.  
  236.         paramPtr^.returnValue := PasToZero(paramPtr, tempStr);
  237.     end;
  238.  
  239.     procedure main (paramPtr: XCmdPtr);
  240.     begin
  241.         NumberToHex(paramPtr);
  242.     end;
  243. end.